import { qrCode } from "./request.js";
import './html2canvas.js';

let data = {};
data.token = sessionStorage.getItem("token");
data.id = sessionStorage.getItem("id");
let viewTime = document.querySelector('.viewTime');
async function getData() {
    let res = await qrCode(data);
    // 加载二维码
    let image = document.querySelector('#qrCode');
    image.src = res.data.data
    let username = document.querySelector('.username');
    username.innerHTML = sessionStorage.getItem('name');
    let seeTime = JSON.parse(sessionStorage.getItem('seeTime'))
    viewTime.innerHTML = `欢迎您在${seeTime[1]}月${seeTime[2]}日${seeTime[3]}参观${seeTime[0]}广州国际花卉艺术展暨中国插花花艺展。`
}
getData();
//返回首页
let homeBtn = document.querySelector('.home');
homeBtn.addEventListener('click', function () {
    location.href = '../index.html';
})
//继续预约
let continueBtn = document.querySelector('.continue');
continueBtn.addEventListener('click', function () {
    location.href = 'chooseday.html';
})
//预约记录
let historyBtn = document.querySelector('.history');
historyBtn.addEventListener('click', function () {
    location.href = 'history.html';
})
//截图canvas
let saveBtn = document.querySelector('.save');
saveBtn.addEventListener('click', function () {
    screenShot();
})
// 生成截图过程
function screenShot() {
    html2canvas(document.body, {
        allowTaint: true,
        useCORS: true
    }).then(canvas => {
        let a = document.createElement('a');
        let img = new Image();
        img.src = canvas.toDataURL();
        a.appendChild(img);
        a.href = img.src;
        a.download = "预约二维码";
        document.body.appendChild(a);
        setTimeout(function () {
            img.style.transform = "scale(0.6)";
        }, 0)
        setTimeout(function () {
            a.click();
            a.remove();
        }, 600)
    });
}


